package com.un.ebs.production.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.un.ebs.production.domain.ProductionWorkOrder;
import com.un.ebs.production.domain.ProductionWorkOrderExt;
import com.un.ebs.production.domain.ProductionWorkOrderOutExt;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * (ProductionWorkOrder)表数据库访问层
 *
 * @author liubo
 * @since 2020-07-07 13:21:07
 */
public interface ProductionWorkOrderMapper extends BaseMapper<ProductionWorkOrder> {

    @SqlParser(filter = true)
    @Select("select * from v_production_work_order_ext where production_order_item_id = #{itemId} order by production_seq_item_code asc")
    List<ProductionWorkOrderExt> selectByItemId(@Param("itemId") String itemId);

    @SqlParser(filter = true)
    @Select("select * from v_production_work_order_ext where production_order_item_id = #{itemId} and production_seq_item_id=#{seqItemId} order by production_seq_item_code asc")
    List<ProductionWorkOrderExt> selectByItemAndSeq(@Param("itemId") String itemId, @Param("seqItemId") String seqItemId);

    @SqlParser(filter = true)
    @Select("select * from v_production_work_order_out_ext where production_order_item_id = #{itemId} and seq_sku_id=#{seqItemRelationSkuId} order by seq_item_code asc")
    List<ProductionWorkOrderOutExt> selectOutByItemId(@Param("itemId") String itemId, @Param("seqItemRelationSkuId") String seqItemRelationSkuId);

    @Delete("delete from tb_quality_check where production_work_order_id in (select id from tb_production_work_order where production_order_item_id = #{productionOrderItemId})")
    void deleteQualityCheck(@Param("productionOrderItemId") String productionOrderItemId);
}